package com.caifu.controller;

import java.util.*;

import javax.servlet.http.HttpServletRequest;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.caifu.pojo.*;
import com.caifu.service.*;
import com.caifu.util.AesMyUtil;
import com.caifu.util.DesUtil;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.caifu.bean.Result;
import com.caifu.bean.ResultUtil;
import com.caifu.util.ShiroUtil;
import com.caifu.util.Util;

import net.sf.json.JSONObject;

/**
 * 功能描述: 用户管理
 * @Author: szt
 * @Date:   2020/11/11
 */
@Controller
@RequestMapping("/user")
public class UserController extends AbstractController {

    final static Logger logger = LoggerFactory.getLogger(UserController.class);

    @Autowired
    private SysUserService userService;
    @Autowired
    private SysOrganizationService orgService;
    @Autowired
    private SysMenuService menuService;
    @Autowired
    private SysRoleService roleService;
    @Autowired
    private SysUserDataAuthService daService;
    @Autowired
    private SysShortMessageService msgService;
    @Autowired
    private SysLogService logService;
    @Autowired
    private SysUserRoleService userRoleService;

    /**
     * 进入用户列表页面
     * 192.168.1.180:9999/ATPension/user/listPage
     * 2020年8月9日 
     * codeBy szt
     */
    @RequestMapping("/listPage")
    //@RequiresPermissions("yonghuguanli")
    //@RequiresPermissions({"yonghuguanli", "yonghuguanli_read"})
    public String listPage(String initPage,ModelMap map){
        try {
        	JSONObject json = orgService.getAllOrganization(null);
			map.put("initPage",initPage);
			map.put("json", json);
		} catch (Exception e) {
			logger.error(e.toString());
		}
        return "view/user/user_list";
    }

    /**
     * 进入用户添加页面
     * 192.168.1.180:9999/ATPension/user/addPage
     * 2020年8月9日
     * codeBy szt
     */
    @RequestMapping("/addPage")
    //@RequiresPermissions("yonghuguanli")
    public String addPage(ModelMap map){ return "view/user/user_add"; }

    /**
     * 获取角色列表
     * 192.168.1.180:9999/ATPension/user/getRoleList
     * 2020年8月11日
     * codeBy szt
     */
    @RequestMapping("/getRoleList")
    @ResponseBody
   // @RequiresPermissions("yonghuguanli")
    public JSONObject getRoleList(String userNo){
        JSONObject json = new JSONObject();
        try{
            List<Map<String,Object>> roleList = roleService.listMaps(new QueryWrapper<SysRole>().select("id,name,preinstall").eq("state","1").orderByAsc("sort"));
            if(StringUtils.isNotBlank(userNo)){
                final String tmpUserNo=DesUtil.decrypt(userNo);
                roleList.forEach(obj->{
                    SysUserRole role = userRoleService.getOne(new QueryWrapper<SysUserRole>().eq("user_id",tmpUserNo).eq("role_id",(Integer)obj.get("id")));
                    if(role!=null){
                        obj.put("authType","1");
                    }else{
                        obj.put("authType","0");
                    }
                });
            }

            json.put("code","0");
            json.put("msg","成功");
            json.put("data",roleList);
            return json;
        }catch (Exception e){
            e.printStackTrace();
            logger.error("获取角色列表失败！");
            json.put("code","1");
            json.put("msg","失败");
            return json;
        }
    }

    /**
     * 获取角色列表
     * 192.168.1.180:9999/ATPension/user/getRoleInfo
     * 2020年8月11日
     * codeBy szt
     */
    @RequestMapping("/getRoleInfo")
    @ResponseBody
    //@RequiresPermissions("yonghuguanli")
    public JSONObject getRoleInfo(String roleNo){
        JSONObject json = new JSONObject();
        try{
           Map<String,Object> map = roleService.getMap(new QueryWrapper<SysRole>().eq("id", roleNo));
            json.put("code","0");
            json.put("msg","成功");
            json.put("info",map);
            return json;
        }catch (Exception e){
            e.printStackTrace();
            logger.error("获取角色信息失败！");
            json.put("code","1");
            json.put("msg","失败");
            return json;
        }
    }



    /**
     * 进入用户修改页面
     * 192.168.1.180:9999/ATPension/user/editPage
     * 2020年8月9日
     * codeBy szt
     */
    @RequestMapping("/editPage")
   // @RequiresPermissions("yonghuguanli")
    public String editPage(String userNo, ModelMap map){
        map.put("userNo",userNo);
        return "view/user/user_add";
    }

    /**
     * 进入用户查询页面
     * 192.168.1.180:9999/ATPension/user/infoPage?userNo=A5D70CFA854ACBCE
     * 2020年8月9日
     * codeBy szt
     */
    @RequestMapping("/infoPage")
    //@RequiresPermissions("yonghuguanli")
    public String infoPage(String userNo, ModelMap map){
        map.put("userNo",userNo);
        return "view/user/user_info";
    }

    /**
     * 进入操作员权限配置
     * 2020年8月11日 
     * codeBy szt
     */
    @RequestMapping("/auth")
    //@RequiresPermissions("yonghuguanli")
    public String auth(String userNo,ModelMap map){

    	Map<String,Object> userMap = userService.getMap(new QueryWrapper<SysUser>().eq("user_no", DesUtil.decrypt(userNo)));
    	String orgName="";
    	if(userMap!=null&&userMap.get("ORG_ID")!=null&&!userMap.get("ORG_ID").equals("")) {
    		SysOrganization org = orgService.getById(Long.parseLong((String)userMap.get("ORG_ID")));
    		orgName = org!=null ?org.getOrgName():"";
    	}
        SysUser user = userService.getById(DesUtil.decrypt(userNo));
        map.put("user", user);
        map.put("userNo", userNo);
        map.put("orgName", orgName);
        return "view/user/auth";
    }
    
    /**
     * 进入操作员个人中心设置
     * 192.168.1.180:9999/caifu/user/person
     * 2020年8月12日 
     * codeBy szt
     */
    @RequestMapping("/person")
   // @RequiresPermissions("gerenzhongxin")
    public String person(ModelMap map) throws Exception {
    	int userNo = getUserNo();
    	  //根据操作员编号获取用户信息
    	Map<String,Object> userMap = userService.getMap(new QueryWrapper<SysUser>().eq("user_no", userNo));
    	String orgName="";
    	if(userMap!=null&&userMap.get("ORG_ID")!=null&&!userMap.get("ORG_ID").equals("")) {
    		SysOrganization org = orgService.getById(Long.parseLong((String)userMap.get("ORG_ID")));
    		orgName = org!=null ?org.getOrgName():"";
    	}
        String phone = (String)userMap.get("PHONE");
        userMap.put("PHONE", AesMyUtil.Decrypt(phone));
        userMap.put("ORG_NAME", orgName);
    	map.addAttribute("map",userMap);
        return "view/user/person";
    }

    /**
     * 获取操作员列表
     * 2020年8月11日 
     * codeBy szt
     */
    @RequestMapping("/getUserList")
    @ResponseBody
    //@RequiresPermissions("yonghuguanli")
    public JSONObject getUserList(int page,int limit,String loginName,String userName, String phone, String postType){
        JSONObject json = new JSONObject();
        try{
            if(StringUtils.isNotBlank(phone)){
                phone=AesMyUtil.Encrypt(phone);
            }
            IPage<Map<String,Object>> userPage = userService.getUserList(page,limit,loginName,userName,phone,postType);
            for (Map<String,Object> tmp:userPage.getRecords()) {
                String tmpPhone = (String)tmp.get("PHONE");
                Integer userNo = (Integer)tmp.get("USER_NO");
                tmp.put("POST",Util.null2EmptyTrim((String)tmp.get("DEPT")+"/"+Util.null2EmptyTrim((String)tmp.get("POST"))));
                tmp.put("PHONE",AesMyUtil.Decrypt(tmpPhone));
                tmp.put("USER_NO", DesUtil.encrypt(userNo+""));
                Date time = (Date) tmp.get("LOGIN_TIME");
                if(time!=null){
                    tmp.put("LOGIN_TIME",Util.dateToString(time,"yyyy-MM-dd HH:mm:ss"));
                }
            }
            json.put("code","0");
            json.put("msg","成功");
            json.put("count",userPage.getTotal());
            json.put("data",userPage.getRecords());
            return json;
        }catch (Exception e){
            e.printStackTrace();
            logger.error("获取用户列表失败！");
            json.put("code","1");
            json.put("msg","失败");
            return json;
        }
    }
    
    /**
     * 新增修改操作员
     * 2020年8月11日 
     * codeBy szt
     */
    @RequestMapping("/save")
    @ResponseBody
    //@RequiresPermissions("yonghuguanli")
    public Result save(String userNo,String userName,String loginName, String post, String dept, String phone, String orgId, String authRole, String authOrg, String postType, String mealName){
        SysUser operUser = null;
        try{
            boolean isNew = true;
            int loginNameCount;

            userNo = StringUtils.isNotBlank(userNo)?DesUtil.decrypt(userNo):"";
            SysUser user = null;
            operUser = userService.getById(getUserNo());
            if(StringUtils.isNotBlank(userNo)) {
                isNew = false;
                //修改操作员信息
                loginNameCount = userService.getCountByLoginName(loginName,userNo);
                if(loginNameCount > 0) {
                    //日志记录  sys 组织架构模块  sys-201 操作员修改
                    SysLog log = new SysLog(getUserNo(), postType,"sys", "sys-201", "9", "用户账号已存在, "+operUser.getLoginName()+"修改操作员失败！", new Date());
                    logService.save(log);
                	return ResultUtil.error(198,"用户账号已存在，修改失败！");
                }
                
                int phoneExistCount = userService.count(new QueryWrapper<SysUser>().eq("phone", AesMyUtil.Encrypt(phone)).eq("post_type",postType).ne("user_no",userNo).ne("status", "9"));
            	if(phoneExistCount>0) {
                    //日志记录  sys 组织架构模块  sys-201 操作员修改
                    SysLog log = new SysLog(getUserNo(), postType,"sys", "sys-201", "9", "手机号已存在, "+operUser.getLoginName()+"修改操作员失败！", new Date());
                    logService.save(log);
                    return ResultUtil.error(199,"手机号已存在，修改失败！");
            	}
  
                user = userService.getById(userNo);
                user.setUpdateBy(getUserNo());
                user.setUpdateTime(new Date());
                user.setLoginName(loginName);
                user.setUserName(userName);
                user.setDept(dept);
                user.setPhone(AesMyUtil.Encrypt(phone));
                user.setPost(post);
                user.setMealName(mealName);
                user.setOrgId(orgId);
            }else{
            	int phoneExistCount = userService.count(new QueryWrapper<SysUser>().eq("phone", AesMyUtil.Encrypt(phone)).eq("post_Type",postType).ne("status", "9"));
            	if(phoneExistCount>0) {
                    //日志记录  sys 组织架构模块  sys-200 操作员添加
                    SysLog log = new SysLog(getUserNo(), postType,"sys", "sys-200", "9", "手机号已存在, "+operUser.getLoginName()+"新增操作员失败！", new Date());
                    logService.save(log);
                    return ResultUtil.error(199,"手机号已存在，保存失败！");
            	}
            	
                //新增操作员信息
                loginNameCount = userService.getCountByLoginName(loginName,null);
                if(loginNameCount <= 0) {
                    user = new SysUser();
                    user.setCreateTime(new Date());
                    user.setLoginName(loginName);
                    user.setUserName(userName);
                    user.setPaw("111111");
                    user.setPost(post);
                    user.setDept(dept);
                    user.setMealName(mealName);
                    user.setPhone(AesMyUtil.Encrypt(phone));
                    String salt = Util.getStringRandom(20);
                    String password = ShiroUtil.sha256("111111", salt);
                    user.setSalt(salt);
                    user.setPassword(password);
                    user.setCreateBy(getUserNo());
                    user.setStatus("1");
                    user.setOrgId(orgId);
                    user.setPostType(postType);
                    user.setPasswordEditFlag("0"); //0-密码未修改
                }else{
                    //日志记录  sys 组织架构模块  sys-200 操作员添加
                    SysLog log = new SysLog(getUserNo(), postType,"sys", "sys-200", "9", "用户账号已存在, "+operUser.getLoginName()+"新增操作员失败！", new Date());
                    logService.save(log);
                    return ResultUtil.error(198,"用户账号已存在,保存失败！");
                }
            }

            userService.saveOrUpdate(operUser,user,isNew,authRole,authOrg,postType);
            if(StringUtils.isNotBlank(userNo)) {
            	 return ResultUtil.success(200, "用户信息修改成功！");
            }else {
            	 return ResultUtil.success(200, "用户信息保存成功！");
            }
           

        }catch (Exception e){
            e.printStackTrace();
            logger.error("用户信息保存失败！");
            return ResultUtil.error(199,"用户信息保存失败！");
        }
    }

    /**
     * 通过操作员编号获取用户信息
     * 2020年8月12日 
     * codeBy szt
     */
    @RequestMapping("/getUserById")
    @ResponseBody
    //@RequiresPermissions("yonghuguanli")
    public Result getUserById(String userNo){
        try{
            //根据操作员编号获取用户信息
        	Map<String,Object> userMap = userService.getMap(new QueryWrapper<SysUser>().eq("user_no", DesUtil.decrypt(userNo)));
        	String postType = String.valueOf(userMap.get("POST_TYPE"));

            String orgName = "";
            if (userMap != null && userMap.get("ORG_ID") != null && !userMap.get("ORG_ID").equals("")) {
                SysOrganization org = orgService.getById(Long.parseLong((String) userMap.get("ORG_ID")));
                orgName = org != null ? org.getOrgName() : "";
            }
            userMap.put("ORG_NAME", orgName);
            String phone = (String)userMap.get("PHONE");
            userMap.put("PHONE",AesMyUtil.Decrypt(phone));
            userMap.put("USER_NO",userNo);
            //获取用户授权角色
            String userRoleSet = userRoleService.getUserRoleSet(DesUtil.decrypt(userNo));
            userMap.put("AUTH_ROLE",userRoleSet);
            return ResultUtil.success(200, "获取用户信息成功！",userMap);
        }catch (Exception e){
            e.printStackTrace();
            logger.error("获取用户信息失败！");
            return ResultUtil.error(199,"获取用户信息失败！");
        }
    }

    @RequestMapping("/setUserMenu")
    @ResponseBody
    //@RequiresPermissions("yonghuguanli")
    public Result setUserMenu(int userNo,String menus){
        try{
            //菜单权限配置
            userService.setUserMenu(userNo,menus);
            return ResultUtil.success(200, "菜单权限配置成功！");
        }catch (Exception e){
            e.printStackTrace();
            logger.error("菜单权限配置失败！");
            return ResultUtil.error(199,"菜单权限配置失败！");
        }
    }

    @RequestMapping("/resetPassword")
    @ResponseBody
    //@RequiresPermissions("yonghuguanli")
    public Result resetPassword(String userNo){
        try{
            //重置密码
            userNo=DesUtil.decrypt(userNo);
            String salt = Util.getStringRandom(20);
            String password = ShiroUtil.sha256("111111", salt);
            return ResultUtil.success(200, "密码重置成功！",userService.update(new UpdateWrapper<SysUser>().lambda().set(SysUser::getPaw,"111111").set(SysUser::getSalt,salt).set(SysUser::getPassword,password).eq(SysUser::getUserNo,userNo)));
        }catch (Exception e){
            e.printStackTrace();
            logger.error("密码重置失败！");
            return ResultUtil.error(199,"密码重置失败！");
        }
    }

    @RequestMapping("/changePassword")
    @ResponseBody
    public Result changePassword(String phone, String newPassword){
        SysUser user = new SysUser();
        try{
            //重置密码
            int userNo = getUserNo();
            user = userService.getOne(new QueryWrapper<SysUser>().eq("phone", phone).eq("post_type","1"));

            String salt = Util.getStringRandom(20);
            String password = ShiroUtil.sha256(newPassword, salt);

            user.setPaw(newPassword);
            user.setPasswordEditFlag("1");
            user.setPassword(password);
            userService.updateById(user);
            //日志记录  sys 组织架构模块  sys-209 修改密码
            SysLog log = new SysLog(getUserNo(), "1","sys", "sys-209", "1", user.getLoginName()+"修改用户密码成功！", new Date());
            logService.save(log);
            return ResultUtil.success(200, "密码修改成功！",userService.update(new UpdateWrapper<SysUser>().lambda().set(SysUser::getPaw,newPassword).set(SysUser::getSalt,salt).set(SysUser::getPassword,password).eq(SysUser::getUserNo,userNo)));
        }catch (Exception e){
            e.printStackTrace();
            logger.error("密码修改失败！");
            //日志记录  sys 组织架构模块  sys-302 修改密码
            SysLog log = new SysLog(getUserNo(), "1","sys", "sys-302", "9", user.getLoginName()+"修改用户密码失败！", new Date());
            logService.save(log);
            return ResultUtil.error(199,"密码修改失败！");
        }
    }
    
    /**
     * 删除操作员
     * 2020年8月11日 
     * codeBy szt
     */
    @RequestMapping("/delete")
    @ResponseBody
   // @RequiresPermissions("yonghuguanli")
    public Result delete(String userNo,String postType){
        SysUser oldUser = new SysUser();
        try{
            userNo = DesUtil.decrypt(userNo);
            oldUser = userService.getById(getUserNo());
            userService.delete(userNo,postType);
            //日志记录  sys 组织架构模块  sys-202 操作员删除
            SysLog log = new SysLog(getUserNo(), "1","sys", "sys-202", "1", oldUser.getLoginName()+"删除操作员成功[userNo="+userNo+"]！", new Date());
            logService.save(log);
            return ResultUtil.success(200, "删除用户成功！");
        }catch (Exception e){
            e.printStackTrace();
            logger.error("删除用户失败！");
            //日志记录  sys 组织架构模块  sys-202 操作员删除
            SysLog log = new SysLog(getUserNo(), "1","sys", "sys-202", "9", oldUser.getLoginName()+"删除操作员失败[userNo="+userNo+"]！", new Date());
            logService.save(log);
            return ResultUtil.error(199,"删除用户失败！");
        }
    }
    
    /**
     * 开通操作员
     * 2020年8月11日 
     * codeBy szt
     */
    @RequestMapping("/open")
    @ResponseBody
    //@RequiresPermissions("yonghuguanli")
    public Result open(String userNo){
        SysUser oldUser = new SysUser();
        try{
            userNo = DesUtil.decrypt(userNo);
            oldUser = userService.getById(getUserNo());
            //日志记录  sys 组织架构模块  sys-207 操作员开通
            SysLog log = new SysLog(getUserNo(), "1","sys", "sys-207", "1", oldUser.getLoginName()+"开通操作员成功[userNo="+userNo+"]！", new Date());
            logService.save(log);
            //逻辑开通
            return ResultUtil.success(200, "开通用户成功！",userService.update(new UpdateWrapper<SysUser>().lambda().set(SysUser::getStatus,"1").eq(SysUser::getUserNo,userNo)));
        }catch (Exception e){
            e.printStackTrace();
            logger.error("开通用户失败！");
            //日志记录  sys 组织架构模块  sys-207 操作员开通
            SysLog log = new SysLog(getUserNo(), "1","sys", "sys-207", "9", oldUser.getLoginName()+"开通操作员失败[userNo="+userNo+"]！", new Date());
            logService.save(log);
            return ResultUtil.error(199,"开通用户失败！");
        }
    }
    
    /**
     * 关闭操作员
     * 2020年8月11日 
     * codeBy szt
     */
    @RequestMapping("/close")
    @ResponseBody
   // @RequiresPermissions("yonghuguanli")
    public Result close(String userNo,String postType){
        SysUser oldUser = new SysUser();
        try{
            userNo = DesUtil.decrypt(userNo);
            oldUser = userService.getById(getUserNo());
            //逻辑关闭
            userService.close(userNo,postType);
            //日志记录  sys 组织架构模块  sys-208 操作员关闭
            SysLog log = new SysLog(getUserNo(), "1","sys", "sys-208", "1", oldUser.getLoginName()+"关闭操作员成功[userNo="+userNo+"]！", new Date());
            logService.save(log);
            return ResultUtil.success(200, "停用用户成功！");
        }catch (Exception e){
            e.printStackTrace();
            logger.error("关闭用户失败！");
            //日志记录  sys 组织架构模块  sys-208 操作员关闭
            SysLog log = new SysLog(getUserNo(), "1","sys", "sys-208", "9", oldUser.getLoginName()+"关闭操作员成功[userNo="+userNo+"]！", new Date());
            logService.save(log);
            return ResultUtil.error(199,"停用用户失败！");
        }
    }

    /**
     * 查询单个菜单
     * 2020年8月12日
     * codeBy szt
     */
    @RequestMapping("/getMenu")
    @ResponseBody
    //@RequiresPermissions("yonghuguanli")
    public Result getUserMenu(String menuNo){
        try{
            SysMenu me = menuService.getOne(new QueryWrapper<SysMenu>().eq("MENU_NO", menuNo));
            return ResultUtil.success(200, "获取菜单成功！",me);
        }catch (Exception e){
            e.printStackTrace();
            logger.error("获取菜单失败！");
            return ResultUtil.error(199,"获取菜单失败！");
        }
    }
    
    /**
     * 获取用户数据权限已赋权组织机构
     * 2020年8月12日 
     * codeBy szt
     */
    @RequestMapping("/getUserAuthOrg")
    @ResponseBody
    //@RequiresPermissions("yonghuguanli")
    public Result setUserAuth(String userNo){
        try{    	
        	List<SysUserDataAuth> list =  daService.list(new QueryWrapper<SysUserDataAuth>().eq("user_no", DesUtil.decrypt(userNo)).eq("type", "1"));
        	return ResultUtil.success(200, "查询成功", list);
        }catch (Exception e){
            logger.error("设置用户权限失败！");
            return ResultUtil.error(199,"设置用户权限失败！");
        }
    }
    
    /**
     * 修改用户手机号
     * 
     * 2020年8月14日 
     * codeBy szt
     */
    @RequestMapping("/editUserPhone")
    @ResponseBody
    //@RequiresPermissions("gerenzhongxin")
    public Result sendRandomCode(String phone, String verifyCode ,HttpServletRequest request){
        try{    
        	JSONObject jsonRet = msgService.checkVerifyCode(phone, verifyCode, request);
			if(!jsonRet.get("code").equals("0000")){
				return ResultUtil.error(199,(String)jsonRet.get("codeDesc"));
			}else {
				 SysUser user = userService.getOne(new QueryWrapper<SysUser>().eq("user_no", getUserNo()));
				 int phoneExistCount = userService.count(new QueryWrapper<SysUser>().eq("phone", AesMyUtil.Encrypt(phone)).ne("user_no",getUserNo()).ne("status", "9"));
            	 if(phoneExistCount>0&&!phone.equals(user.getPhone())) {
                     //日志记录  sys 组织架构模块  sys-301 修改手机号
                     SysLog log = new SysLog(getUserNo(), "1","sys", "sys-301", "9", user.getLoginName()+"手机号已存在, 修改用户手机号失败！", new Date());
                     logService.save(log);
            		 return ResultUtil.error(199,"手机号已存在，修改失败！");
            	 }else {
            		 user.setPhone(AesMyUtil.Encrypt(phone));
            		 userService.updateById(user);
                     //日志记录  sys 组织架构模块  sys-301 修改手机号
                     SysLog log = new SysLog(getUserNo(), "1","sys", "sys-301", "1", user.getLoginName()+"修改用户手机号成功！", new Date());
                     logService.save(log);
                     //绑定微信账户
                     userService.bindSysWechatUser(user.getUserNo()+"");
            		 return ResultUtil.success(200, "修改成功");
            	 }
	  	
			}
			
        }catch (Exception e){
            logger.error("修改手机号失败！");
            return ResultUtil.error(199,"修改失败！");
        }
    }
    
    /**
     * 修改用户头像
     * 
     * 2020年8月14日 
     * codeBy szt
     */
    @RequestMapping("/editUserPhoto")
    @ResponseBody
   // @RequiresPermissions("gerenzhongxin")
    public Result editUserPic(String userPhoto ,HttpServletRequest request){
        SysUser user = new SysUser();
        try{    
			 user = userService.getOne(new QueryWrapper<SysUser>().eq("user_no", getUserNo()));
    		 user.setUserPhoto(userPhoto);
    		 userService.updateById(user);
            //日志记录  sys 组织架构模块  sys-300 修改用户头像
            SysLog log = new SysLog(getUserNo(), "1","sys", "sys-300", "1", user.getLoginName()+"修改用户头像成功！", new Date());
            logService.save(log);
    		 return ResultUtil.success(200, "修改成功");
        }catch (Exception e){
            logger.error("修改用户头像失败！");
            //日志记录  sys 组织架构模块  sys-300 修改用户头像
            SysLog log = new SysLog(getUserNo(), "1","sys", "sys-300", "9", user.getLoginName()+"修改用户头像失败！", new Date());
            logService.save(log);
            return ResultUtil.error(199,"修改失败！");
        }
    }

}
